const md5 = require("md5");

const SALT = "gt";

// md5 加密
const md5Password = (password) => {
  return new Promise((resolve, reject) => {
    const md5PWD = md5(password + SALT);
    resolve(md5PWD);
  });
};

// 密码验证
const matchPassword = (oldMd5Pwd, password) => {
  return new Promise((resolve, reject) => {
    const newMd5PWD = md5(password + SALT);
    if (oldMd5Pwd === newMd5PWD) {
      resolve(true);
    } else {
      resolve(false);
    }
  });
};

module.exports = {md5Password,matchPassword};

// // 测试
// async function test1() {
//   const password = "gt";
//   const md51 = await md5Password(password);
//   console.log("md51:", md51);
//   const md52 = await matchPassword(md51, "gt");
//   console.log("md52:", md52);
// }
// test1();
